library(tidyverse)
library(fixest)
library(showtext)
library(vtable)
library(writexl)
library(haven)
library(gridExtra)

setwd('D:\\WorkingPaper-Series\\Township_Light\\Replication_Files\\workdata')

##################################
########## Figure C3 #############
##################################

twfe_no_trend_light <- read_delim('twfe_replace_trend_light.csv')

twfe_no_trend_light <- twfe_no_trend_light %>% mutate(upper_ci = coef + 1.96*std_err, lower_ci = coef - 1.96*std_err) %>% 
  filter(period>=-5&period<=5)

twfe_no_trend_light %>% ggplot(aes(period,coef,color = outcome,group = outcome))+
  geom_hline(yintercept = 0,color = 'black', lwd = 0.5, lty = 2)+
  geom_vline(xintercept = -1, color = 'grey50', lwd = 0.5, lty = 4)+
  geom_errorbar(aes(ymin = lower_ci, ymax = upper_ci), width=.2, lwd = .3,position=position_dodge(0.3))+
  geom_point(aes(shape = outcome, color = outcome, fill = outcome),position=position_dodge(0.3)) +
  theme_bw()+
  theme(legend.position = c(0.15,0.2),
        legend.background = element_rect(color = 'black', size = 0.1,linewidth = 0.1, fill = 'white'),
        legend.margin = margin(t = -0.45, r = 0.1, b = 0, l = 0.1, unit = "cm"),
        text = element_text(family = 'serif',size = 10),
        axis.text =  element_text(family = 'serif',size = 8))+
  labs(y = '', x = 'Relative Time') +
  scale_x_continuous(breaks = c(seq(-5,5,1)), labels = c('-5+','-4','-3','-2','-1','0','1','2','3','4','5+'))+
  scale_y_continuous(limits = c(-0.2,0.1))+
  scale_color_manual(values = c('log (light+1)' = 'black', 'IHS (light)' = '#1C398E')) +
  scale_fill_manual(values = c('log (light+1)' = 'black', 'IHS (light)' = '#1C398E')) +
  scale_shape_manual(values = c('log (light+1)' = 21, 'IHS (light)' = 23)) +
  guides(colour = guide_legend(""),fill = guide_legend(""),shape = guide_legend(""))
